<template>
  <slot></slot>
</template>

<script lang="ts" setup>
import { onBeforeMount, useSlots } from "vue"
import { Window } from "@/core/window/window"

const props = defineProps({
  window: {
    type: Object as () => Window,
    required: true
  }
})

const slots = useSlots()
onBeforeMount(() => {
  const vNodes = slots.default?.()
  vNodes?.forEach((vNode) => {
    vNode.props!.onMousedown = (event: MouseEvent) => startDrag(event)
    vNode.props!.onDblclick = () => props.window.switchMaximize()
    vNode.props!.style = {
      "user-select": "none"
    }
  })
})

function startDrag(event: MouseEvent) {
  props.window.startResize("move", event)
}
</script>

<style scoped></style>
